﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;

namespace CafeTek
{
    public partial class FrmStatistic : Form
    {
        private DateTimePicker dtpFrom = null;
        private DateTimePicker dtpTo = null;
        BillDB billDb = null;
        DataView dv =null;
        public FrmStatistic()
        {
            ToolStripControlHost tsHost = null;

            InitializeComponent();

            //create date TimePicker dtpFrom
            dtpFrom = new DateTimePicker();
            dtpFrom.Size = new Size(90, 22);
            dtpFrom.Format = DateTimePickerFormat.Custom;
            dtpFrom.CustomFormat = "dd/MM/yyyy";
            dtpFrom.Value = DateTime.Today;
            tsHost = new ToolStripControlHost(dtpFrom, "dtpFrom");
            this.tbrMain.Items.Insert(this.tbrMain.Items.IndexOf(tbrLblFrom) + 1, tsHost);

            //create date TimePicker dtpTo
            dtpTo = new DateTimePicker();
            dtpTo.Size = new Size(90, 22);
            dtpTo.Format = DateTimePickerFormat.Custom;
            dtpTo.CustomFormat = "dd/MM/yyyy";
            dtpTo.Value = DateTime.Today;
            tsHost = new ToolStripControlHost(dtpTo, "dtpTo");
            this.tbrMain.Items.Insert(this.tbrMain.Items.IndexOf(tbrLblTo) + 1, tsHost);
        }

        private void FrmStatistic_Load(object sender, EventArgs e)
        {
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (dv == null)
                return;

            FrmPrintPay f = new FrmPrintPay();
            f.PrintTotal(dv);
            f.Show();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            decimal sumPrice = 0;
            billDb = new BillDB();
            dv = new DataView(billDb.TotalPrice(this.dtpFrom.Value, this.dtpTo.Value));

            dataGridView1.DataSource = dv;
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                sumPrice += decimal.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());                
            }
            lblRevenue.Text = "Revenue: " + sumPrice.ToString();
        }

        private void btnToday_Click(object sender, EventArgs e)
        {
            decimal sumPrice = 0;
            billDb = new BillDB();
            dv = new DataView(billDb.TotalPrice(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year));

            dataGridView1.DataSource = dv;
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                sumPrice += decimal.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());                
            }
            lblRevenue.Text = "Revenue: " + sumPrice.ToString();
        }
    }
}
